import 'dart:ui';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:magic_car/util/ToastUtil.dart';
import 'package:magic_car/util/colors.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:magic_car/main.dart';
import 'package:toast/toast.dart';
import 'package:dio/dio.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'dart:async';

class UUserPage extends StatefulWidget {
  UUserPage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<UUserPage> {
  Map userinfo = new Map();
  File _image;
  String avatar = '';

  @override
  void initState() {
    super.initState();
    loaduserinfo();
  }

  loaduserinfo() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    Map<String, String> map = new Map();
    map["id"] = pref.getString('uid');

    HttpHelper.post(HttpHelper.API_Userinfo, (data) async {
      if (data != null) {
        print(data);
        //Toast.show(data["msg"], context);

        if (data["code"].toString() == "1") {
          if (data["info"]["avatar"].length != 0) {
            setState(() {
              avatar = data["info"]["avatar"];
            });
          }
          setState(() {
            userinfo = data["info"];
          });
          //pref.setStringList('userinfo', data["info"]);

        }
      }
    }, params: map);
  }

  //更新头像信息
  uploadAvatar() async {
    SharedPreferences pref = await SharedPreferences.getInstance();
    Map<String, String> map = new Map();
    map["id"] = pref.getString('uid');
    map["avatar"] = avatar;

    HttpHelper.post(HttpHelper.API_UpdateAvatar, (data) async {
      if (data != null) {
        print(data);
        Toast.show(data["msg"], context);
      }
    }, params: map);
  }

  //选择图片
  getimgs(type) async {
    if (type == 1) {
      var image = await ImagePicker.pickImage(source: ImageSource.gallery);

      setState(() {
        _image = image;
      });
    } else {
      var image = await ImagePicker.pickImage(source: ImageSource.camera);

      setState(() {
        _image = image;
      });
    }

    if (_image == null) return;
    Map<String, String> map = new Map();
    HttpHelper.upLoadImage(_image, (data) {
      if (data.containsKey('code')) {
        Toast.show(data['msg'], context);
      } else {
        setState(() {
          avatar = data['url'];
        });
        uploadAvatar();
      }
    }, params: map);
  }

//选择图片方式
  Future getImage() async {
    showDialog(
        context: context,
        builder: (BuildContext context) {
          return new SimpleDialog(
            title: new Text('选择'),
            children: <Widget>[
              new SimpleDialogOption(
                child: new Text('相机'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(0);
                },
              ),
              new SimpleDialogOption(
                child: new Text('相册'),
                onPressed: () {
                  Navigator.pop(context);
                  getimgs(1);
                },
              )
            ],
          );
        });
    // var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    // //_upLoadImage(image);//上传图片
    // setState(() {
    //   _image = image;
    // });
  }
  // uploadimg() async{
  //   Map<String, String> map = new Map();
  // // Navigator.of(context).pop();
  // HttpHelper.upLoadImage(_files, (data)  {
  //   // Navigator.of(context).pop();

  //   var carnum = "";
  //   var imagepath = "";
  //   _alert(data["errorMessage"]);
  //   if (data["code"] == 1) {
  //   } else {
  //     carnum = data["data"]["car_number"];
  //     imagepath = data["data"]["image_url"];
  //   }

  //   // loadingPage.close();
  //   for(var addressitem in _address){
  //     if(addressitem["road"]["name"]==currentAdd){
  //       address_Id = addressitem["road"]["id"];
  //     }
  //   }
  //   Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
  //     return new CarNumPage(carnum, imagepath,address_Id,currentAdd);
  //   }));
  //   // _alert(data["errorMessage"]);
  // }, params: map);
  // }

  Widget build(BuildContext context) {
    return
        // new MaterialApp(
        //     title: '个人中心',
        //     home:
        new Scaffold(
            appBar: new AppBar(
                actions: <Widget>[
                  // IconButton(
                  //   icon: Icon(Icons.help),
                  //   onPressed: () {},
                  // ),
                  IconButton(
                    icon: Icon(
                      Icons.message,
                      color: Colors.white,
                    ),
                    onPressed: () {
                      Navigator.pushNamed(context, "message");
                    },
                  ),
                ],

                // title:Center(child: new Text('个人中心')),
                backgroundColor: Colours.app_main,
                elevation: 0),
            body:
                //     SingleChildScrollView(
                //       scrollDirection: Axis.vertical,
                // //true 滑动到底部
                // reverse: false,
                // padding: EdgeInsets.all(0.0),
                // physics: BouncingScrollPhysics(),
                // child:
                new ListView(children: <Widget>[
              Container(
                  height: 230,
                  child: Stack(children: <Widget>[
                    Positioned(
                      top: 0,
                      left: 0,
                      right: 0,
                      // child:
                      // Center(
                      child: new Container(
                          color: Colours.app_main,
                          height: 150,
                          // width: double.infinity,
                          child: Text('')),
                    ),
                    // Positioned(
                    //   top: 0,
                    //   right: 10,
                    //   child: new Text("消息中心")),
                    Positioned(
                      top: 80.0,
                      left: 20,
                      right: 20,
                      child: new Container(
                        height: 150,
                        decoration: new BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(Radius.circular(5)),
                            border:
                                new Border.all(width: 0, color: Colors.white)),
                        child: Column(
                          children: <Widget>[
                            Padding(
                              padding: new EdgeInsets.fromLTRB(0, 60, 0, 0),
                              child: Text(
                                userinfo.length != 0 ? userinfo["name"] : "用户名",
                                style: TextStyle(fontSize: 18),
                              ),
                            ),
                            userinfo.length != 0
                                ? Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(0, 10, 0, 0),
                                    child: Row(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: <Widget>[
                                        Align(
                                          child: Text(
                                              '已检测车源 ' + userinfo['ordernum'],
                                              style: new TextStyle(
                                                  fontSize: 12,
                                                  color: Colours.app_main)),
                                          alignment: Alignment.centerRight,
                                        ),
                                        // Padding(
                                        //   padding: new EdgeInsets.fromLTRB(
                                        //       10, 0, 0, 0),
                                        //   child: Text(
                                        //       '上架车源 ' + userinfo['online_num'],
                                        //       style: new TextStyle(
                                        //           fontSize: 12,
                                        //           color: Color.fromRGBO(
                                        //               7, 169, 251, 1))),
                                        // ),
                                        // Padding(
                                        //   padding: new EdgeInsets.fromLTRB(
                                        //       10, 0, 0, 0),
                                        //   child: Text(
                                        //       '保修量 ' + userinfo['guratee_num'],
                                        //       style: new TextStyle(
                                        //           fontSize: 12,
                                        //           color: Color.fromRGBO(
                                        //               7, 169, 251, 1))),
                                        // ),
                                      ],
                                    ))
                                : new Text(''),
                            // Padding(
                            //     padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
                            //     child: Row(
                            //       crossAxisAlignment: CrossAxisAlignment.center,
                            //       mainAxisAlignment: MainAxisAlignment.center,
                            //       children: <Widget>[
                            //         Expanded(
                            //           flex: 1,
                            //           child: Align(
                            //             child: Text('898'),
                            //             alignment: Alignment.centerRight,
                            //           ),
                            //         ),
                            //         Expanded(
                            //           flex: 1,
                            //           child: Text(' 极好'),
                            //         )
                            //       ],
                            //     )),
                            // Padding(
                            //   padding: new EdgeInsets.fromLTRB(0, 5, 0, 0),
                            //   child: Text(
                            //     '信用分',
                            //     style: TextStyle(fontSize: 12,color: Color.fromRGBO(153, 153, 153, 1)),
                            //   ),
                            // ),
                          ],
                        ),
                      ),
                    ),
                    Positioned(
                        top: 30.0,
                        left: MediaQuery.of(context).size.width / 2 - 50,
                        child: Center(
                            child: new GestureDetector(
                          onTap: () {
                            //选择图片
                            // getImage();
                            Navigator.pushNamed(context, 'editinfo');
                          },
                          child: Container(
                              width: 100,
                              height: 100,
                              decoration: new BoxDecoration(
                                //背景
                                color: Colors.white,
                                //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                                borderRadius:
                                    BorderRadius.all(Radius.circular(50)),
                                //设置四周边框
                                border: new Border.all(
                                    width: 0.5, color: Colors.white),
                              ),
                              child: ClipRRect(
                                  borderRadius: BorderRadius.circular(50),
                                  child: avatar == ""
                                      ? Image.asset(
                                          "resource/images/user/user1.png")
                                      : CachedNetworkImage(
                                          imageUrl: avatar,
                                          fit: BoxFit.cover,
                                        )
                                  // FadeInImage.assetNetwork(
                                  //   placeholder: "resource/images/user/user1.png",
                                  //   image: avatar,
                                  //   fit: BoxFit.cover,
                                  // ),
                                  // child: avatar == ""
                                  //     ? new Image.asset(
                                  //         'resource/images/user/user1.png')
                                  //     : new Image.network(avatar,height: 100,width: 100,fit: BoxFit.cover),
                                  )),
                        )))
                  ])),
              Padding(
                  padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
                  child: Container(
                    height: 458,
                    child: Stack(
                      children: <Widget>[
                        Positioned(
                          top: 0.0,
                          left: 20,
                          right: 20,
                          child: new Container(
                            height: 458,
                            decoration: new BoxDecoration(
                                color: Colors.white,
                                borderRadius:
                                    BorderRadius.all(Radius.circular(5)),
                                border: new Border.all(
                                    width: 0, color: Colors.white)),
                            child: Column(
                              children: <Widget>[
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //检测记录
                                        print('点击检测记录');
                                        Navigator.pushNamed(
                                            context, "ensurancelist");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/jiance/jiance_sel.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '保修订单                               ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //联系我们//painter
                                        Navigator.pushNamed(context, "contact");
                                        //Navigator.pushNamed(context, "painter");
                                        //Navigator.push(con, route)
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/lianxi.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '联系我们                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //设置
                                        Navigator.pushNamed(context, "wallet");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/wallets.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '我的钱包                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //查询车辆历史信息

                                        Navigator.pushNamed(
                                            context, "querycarinfopage");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/querycarinfo.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '查询车况                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //考试记录testrec
                                        Navigator.pushNamed(context, "testrec");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/testrec.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '考试记录                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      onTap: () {
                                        //学习资料
                                        Navigator.pushNamed(context, "study");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/jilu.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '学习资料                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        // if(userinfo['isInspector'].toString()=="0"){
                                        //   Toast.show('您还不是正式检测师！', context);
                                        //   return;
                                        // }
                                        //设置
                                        Navigator.pushNamed(context, "code");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/code.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '我的二维码                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //设置
                                        Navigator.pushNamed(context, "task");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/task.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '任务中心                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                                Container(
                                  height: 1,
                                  color: Color.fromRGBO(245, 245, 245, 1),
                                ),
                                Padding(
                                    padding:
                                        new EdgeInsets.fromLTRB(15, 0, 15, 0),
                                    child: GestureDetector(
                                      behavior: HitTestBehavior.opaque,
                                      onTap: () {
                                        //设置
                                        Navigator.pushNamed(context, "set");
                                      },
                                      child: Row(
                                        // crossAxisAlignment: CrossAxisAlignment.start,
                                        // mainAxisAlignment: MainAxisAlignment.start,
                                        children: <Widget>[
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment: Alignment.centerLeft,
                                                child: Image.asset(
                                                  'resource/images/user/set.png',
                                                  height: 50,
                                                ),
                                              )),
                                          Expanded(
                                              flex: 7,
                                              child: Align(
                                                  alignment:
                                                      Alignment.centerLeft,
                                                  child: Text(
                                                    '关于我们                                       ',
                                                    style: TextStyle(
                                                        fontSize: 16,
                                                        color: Color.fromRGBO(
                                                            123, 123, 123, 1)),
                                                  ))),
                                          Expanded(
                                              flex: 1,
                                              child: Align(
                                                alignment:
                                                    Alignment.centerRight,
                                                child: Image.asset(
                                                  'resource/images/user/detail.png',
                                                  height: 20,
                                                ),
                                              ))
                                        ],
                                      ),
                                    )),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  )),
              Padding(
                  padding: new EdgeInsets.fromLTRB(0, 10, 0, 0),
                  child: Container(
                    padding: new EdgeInsets.fromLTRB(20, 0, 20, 0),
                    height: 50,
                    decoration: new BoxDecoration(
                        // color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(5)),
                        border: new Border.all(width: 0, color: Colors.white)),
                    child: SizedBox(
                        width: double.infinity,
                        height: 50,
                        child: new FlatButton(
                          child: Text(
                            '退出登录',
                            style: TextStyle(
                                color: Color.fromRGBO(102, 102, 102, 1),
                                fontSize: 16),
                          ),
                          color: Colors.white,
                          textColor: Colors.black,
                          onPressed: () async {
                            SharedPreferences pref =
                                await SharedPreferences.getInstance();
                            pref.clear();
                            Navigator.of(context).pushAndRemoveUntil(
                                new MaterialPageRoute(
                                    builder: (context) => new MyApp()),
                                (route) => route == null);
                          },
                        )),
                  ))
            ]));
  }
}
